package com.caigou.modules.forum.ui.comment

import androidx.activity.viewModels
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.caigou.comm.base.bean.AppBackgroundInfo
import com.caigou.comm.base.constants.AppConstants
import com.caigou.comm.base.constants.RouterPath
import com.caigou.comm.base.container.BaseReplyActivity
import com.caigou.comm.base.ext.observe
import com.caigou.modules.forum.viewmodel.NoticeViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.io.File

/**
 * @author #Suyghur.
 * Created on 2021/12/03
 */
@Route(path = RouterPath.Forum.PAGE_NOTICE_REPLY)
@AndroidEntryPoint
class NoticeReplyActivity : BaseReplyActivity() {

    private val noticeViewModel: NoticeViewModel by viewModels()

    @JvmField
    @Autowired(name = AppConstants.DATA_ID)
    var noticeId = 0

    override fun initView() {
        super.initView()
        binding.replyBtnSubmit.setOnClickListener {
            val content = binding.replyEtContent.text.toString()
            val files: MutableList<File> = mutableListOf()
            urls.forEach {
                files.add(File(it))
            }
            noticeViewModel.setNoticeReply(content, files, AppBackgroundInfo.instance.userBean!!.userId, noticeId)
        }
    }

    override fun observeViewModel() {
        observe(noticeViewModel.noticeReplyLiveData, ::handleSetReply)
    }
}